<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>2-Promise基本用法</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style></style>
  </head>
  <body>
    <div id="app"></div>
    <script>
      var pMise = new Promise(function (resolve, reject) {
        setTimeout(function () {
          var flag = true; // false返回异常， true返回正常
          if (flag) {
            resolve('返回正确的结果');
          } else {
            reject('返回异常的结果');
          }
        }, 100);
      });
      pMise.then(
        function (data) {
          console.log(data);
        },
        function (info) {
          console.log(info);
        }
      );
    </script>
  </body>
</html>
